package
{
	public class ShelfData
	{
		private var data:Array;
		
		public function ShelfData()
		{
			data = new Array();
		}
		
		public function addVariable(n:String, v:String=null):void
		{
			data.push({name:n, value:v});
		}
		
		public function clear():void
		{
			data = new Array();
		}
		
		public function copy():ShelfData
		{
			var sd:ShelfData = new ShelfData();
			for each (var obj:Object in data) {
				sd.addVariable(obj.name, obj.value);
			}
			return sd;
		}
		
		public function getValue(name:String):String
		{
			for each (var obj:Object in data) {
				if (obj.name == name) {
					return obj.value;
				}
			}
			return null;
		}
		
		public function unbrokenAttribute():String
		{
			for(var i:Number = 0; i < data.length; i++)
			{
				var nameValue:Object = data[i];
				if(nameValue.value == null)
				{
					return nameValue.name;
				}
			}
			
			return null;
		}
		
		public function numAssigned():Number
		{
			var total:Number = 0;
			
			for(var i:Number = 0; i < data.length; i++)
			{
				var nameValue:Object = data[i];
				if(this.nameValueHasValue(nameValue))
				{
					total++;
				}
			}
			
			return total;
		}
		
		public function unassignedArray():Array
		{
			var unsetArray:Array = new Array();
			
			for(var i:Number = 0; i < data.length; i++)
			{
				var nameValue:Object = data[i];
				if(!this.nameValueHasValue(nameValue))
				{
					unsetArray.push(nameValue.name);
				}
			}
			
			return unsetArray;
		}
		
		public function nameValueHasValue(nameValue:Object):Boolean
		{
			var value:String = nameValue.value;
			return value != null && value.length > 0;
		}
		
		public function whereArray():Array
		{
			var valuesArray:Array = new Array;
			
			for(var i:Number = 0; i < data.length; i++)
			{
				var nameValue:Object = data[i];
				if(this.nameValueHasValue(nameValue))
				{
					valuesArray.push(nameValue);
				}
			}
			
			return valuesArray;
		}
		
		public function getNames():Array
		{
			var arr:Array = new Array();
			for each (var obj:Object in data) {
				arr.push(obj.name);
			}
			return arr;
		}
		
		public function getData():Array
		{
			return data;
		}
		
		public function toString():String
		{
			var s:String = "";
			for each (var obj:Object in data) {
				s += obj.name + ":" + obj.value + ", ";
			}
			return s;
		}
	}
}